﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace SharpCmd
{
    internal class CheatHandler
    {
        private const int CHEAT_COUNT = 1;

        private string[] cheatCodes = { "SNAKE" };
        private int[] cheatKeyIndexes = { 0 };

        public void KeyPress(char c)
        {
            for (int cheatIdx = 0; cheatIdx < CHEAT_COUNT; cheatIdx++)
            { //for each cheat code
                if (cheatCodes[cheatIdx][cheatKeyIndexes[cheatIdx]] == c)
                { //we have hit the next key in sequence
                    if (++cheatKeyIndexes[cheatIdx] == cheatCodes[cheatIdx].Length)
                    { //are we in the end?
                        if (cheatIdx == 0)
                        {
                            EasterEggs.SnakeForm snake = new EasterEggs.SnakeForm();
                            snake.ShowDialog();
                        }
                        //reset cheat index so we can enter it next time
                        cheatKeyIndexes[cheatIdx] = 0;
                    }
                }
                else //mistyped, reset cheat index
                    cheatKeyIndexes[cheatIdx] = 0;
            }
        }
    }
}